package com.olympia.myapp.xml;

import java.util.List;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

import com.olympia.myapp.entity.Player;

public class MyXMLParser {
	/**
	 * 
	 * @param input
	 * @return
	 */
	public static List<String> parseLoginData(InputSource input) {
		List<String> arrRs = null;
		SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
		SAXParser saxparser;
		try {
			saxparser = saxParserFactory.newSAXParser();
			XMLReader xmlReader = saxparser.getXMLReader();
			LoginXMLHandler lgXMlHandle = new LoginXMLHandler();
			xmlReader.setContentHandler(lgXMlHandle);
			xmlReader.parse(input);

			arrRs = lgXMlHandle.rsLogin;
		} catch (ParserConfigurationException e) {
		} catch (SAXException e) {
		} catch (Exception e) {
			e.printStackTrace();
		}
		return arrRs;
	}

	/**
	 * Top Ten
	 * 
	 * @param input
	 * @return
	 */
	public static List<Player> parseLayerTopData(InputSource input) {
		List<Player> arrRs = null;
		SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
		SAXParser saxparser;
		try {
			saxparser = saxParserFactory.newSAXParser();
			XMLReader xmlReader = saxparser.getXMLReader();
			LayerTopXMLHandler layerXMlHandle = new LayerTopXMLHandler();
			xmlReader.setContentHandler(layerXMlHandle);
			xmlReader.parse(input);

			arrRs = layerXMlHandle.rsPlayers;
		} catch (ParserConfigurationException e) {
		} catch (SAXException e) {
		} catch (Exception e) {
			e.printStackTrace();
		}
		return arrRs;
	}

	/**
	 * All Question
	 * 
	 * @param input
	 * @return
	 */
	public static void parseQuestionData(InputSource input) {
		SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
		SAXParser saxparser;
		try {
			saxparser = saxParserFactory.newSAXParser();
			XMLReader xmlReader = saxparser.getXMLReader();
			QuestionXMLHandler qsXMlHandle = new QuestionXMLHandler();
			xmlReader.setContentHandler(qsXMlHandle);
			xmlReader.parse(input);
		} catch (ParserConfigurationException e) {
		} catch (SAXException e) {
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
